home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / BORL_TIP / TI1000 / TI1760.ASC < prev    next >
Text File  |  1994-01-10  |  2KB  |  133 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland Pascal                        NUMBER  :  1760
  9.   VERSION  :  7.0
  10.        OS  :  DOS
  11.      DATE  :  January 10, 1994                         PAGE  :  1/2
  12.  
  13.     TITLE  :  Creating a temporary stack in real or protected mode
  14.  
  15.  
  16.  
  17.  
  18.   {
  19.   The following code shows how to create a temporary stack
  20.   for use during ISRs and in other situations where the
  21.   default stack might not be big enough.
  22.  
  23.   The following program intentionally creates a very small
  24.   default stack by using the $M compiler directive. It then
  25.   calls a function which pushes $2000 bytes onto the stack,
  26.   thereby setting up a situation which should cause a 202 error.
  27.  
  28.   To avoid the error, the program creates a temporary stack
  29.   by allocating $4000 bytes on the heap and moving this value
  30.   into SS. It then sets SP to point at the end of this new
  31.   stack and proceeds to call the function, which does not
  32.   fail because of the new temporary stack.
  33.  
  34.   This code has been tested in both real and protected mode.
  35.   }
  36.  
  37.  
  38.   {$M $800, 0, $12000}
  39.  
  40.   procedure BreakDefaultStack;
  41.   var
  42.     a:array[0..$2000] of char;
  43.   begin
  44.     Writeln('Hello');
  45.   end;
  46.  
  47.   var
  48.     aSS, aSP: Word;
  49.     Stck: pointer;
  50.  
  51.   begin
  52.     getmem(Stck, $4000);
  53.     Word (Stck^) := 1;
  54.  
  55.     asm
  56.       mov aSP, sp
  57.       mov ax, ss
  58.       mov aSS, ax
  59.       mov ax, word ptr [Stck]
  60.       mov bx, word ptr [stck+2]
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland Pascal                        NUMBER  :  1760
  75.   VERSION  :  7.0
  76.        OS  :  DOS
  77.      DATE  :  January 10, 1994                         PAGE  :  2/2
  78.  
  79.     TITLE  :  Creating a temporary stack in real or protected mode
  80.  
  81.  
  82.  
  83.  
  84.       add ax, $4000-2
  85.       cli
  86.       mov ss, bx
  87.       mov sp, ax
  88.       sti
  89.     end;
  90.  
  91.     BreakDefaultStack;
  92.  
  93.     asm
  94.       mov ax, aSS
  95.       mov ss, ax
  96.       mov sp, aSP
  97.     end;
  98.  
  99.     freemem(Stck, $4000);
  100.   end.
  101.  
  102.   DISCLAIMER: You have the right to use this technical information
  103.   subject to the terms of the No-Nonsense License Statement that
  104.   you received with the Borland product to which this information
  105.   pertains.
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.